#include<bits/stdc++.h>
#define int long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=2e5+5,Mod=998244353;
//char buf[(1<<21)+5],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
inline void Add(int &x,int y){(x=x+y+Mod)%=Mod;}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
bool SSS;
int n;
char s[N];
bool TTT;
inline int ksm(int a,int b){
	int res=1;
	while(b){
		if(b&1) res=res*a%Mod;
		a=a*a%Mod;
		b>>=1;
	}
	return res;
}
int mp[1005][1005];
int dp[1005][1005];
map<vector<int>,int>ff;
signed main(){
	//~ cerr<<(&TTT-&SSS)/1024/1024<<"Mib";
	freopen("song.in","r",stdin);
	freopen("song.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	scanf("%s",s+1);
	n=strlen(s+1);
	bool flag=0;
	For(i,2,n){
		if(s[i]==s[i-1])flag=1;
	}
	if(!flag){
		int tot=0;
		For(i,1,n)if(s[i]=='B'&&s[i+1]=='A')tot++;
		printf("%lld ",tot+1);
		return 0;
	}
	For(i,1,n){
		if(s[i]==s[i+1]) mp[i][i+1]=1;
		if(s[i]=='B'&&s[i+1]=='A') mp[i][i+1]=1;
	}
	For(i,0,n+1)For(j,0,n+1) if(i>j) mp[i][j]=1;
	For(k,4,n){
		For(j,1,n){
			if(j+k-1>n) break;
			if(mp[j+1][j+k-2]==1){
				if(s[j]==s[j+k-1]) mp[j][j+k-1]=1;
				if(s[j]=='B'&&s[j+k-1]=='A')mp[j][j+k-1]=1;
			}
			if(mp[j][j+k-3]==1){
				if(s[j+k-2]==s[j+k-1]) mp[j][j+k-1]=1;
				if(s[j+k-2]=='B'&&s[j+k-1]=='A')mp[j][j+k-1]=1;
			}
			if(mp[j+2][j+k-1]==1){
				if(s[j]==s[j+1]) mp[j][j+k-1]=1;
				if(s[j]=='B'&&s[j+2]=='A')mp[j][j+k-1]=1;
			}
			if(mp[j][j+k-1]) continue;
			For(t,j+1,j+k-2){
				if(mp[j][t]&&mp[t+1][j+k-1]){
					mp[j][j+k-1]=1;
					break;
				}
			}
		}
	}
	if(n<=20){
		int ans=0;
		For(i,0,(1<<n)-1){
			int last=0;
			bool flag=0;
			For(j,1,n){
				if(i&(1<<(j-1))){
					if(mp[last+1][j-1]==0){flag=1;break;} 
					last=j;
				}
			}
			if(mp[last+1][n]==0||flag){flag=1;continue;} 
			vector<int>q;
			For(j,1,n){
				if(i&(1<<(j-1))){
					if(s[j]=='A') q.push_back(1);
					else q.push_back(2);
				}
			}if(ff.count(q))continue;
			ff[q]=1;
			//~ for(auto v:q) cout<<v<<" ";puts("");
			ans++;
		}
		printf("%lld\n",ans);
		return 0;
	}
	dp[0][0]=1;
	For(i,0,n){
		For(k,1,n+1){
			if(dp[i][k-1]==0) continue;
			For(j,i+1,n){
				if((mp[i+1][j-1]&&s[j]=='A')){
					if(j!=n+1)(dp[j][k]+=dp[i][k-1])%=Mod;
					break;
				}
			}
			For(j,i+1,n+1){
				if((mp[i+1][j-1]&&s[j]=='B')){
					if(j!=n+1)(dp[j][k]+=dp[i][k-1])%=Mod;
					break;
				}
			}
			if(mp[i+1][n])(dp[n+1][k-1]+=dp[i][k-1])%=Mod;
		}
	}
	int ans=0;
	//~ For(i,0,n+1){
		For(k,0,n+1)ans+=dp[n+1][k],ans%=Mod;
		//~ For(k,0,n+1)printf("%lld ",dp[i][k]);
		//~ puts("");
	//~ }
	printf("%lld\n",ans);
	//~ For(i,1,1000)printf("%lld %lld\n",i,ksm(2,i));
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}
//1 2 4 19 239
